import React, { Component } from "react";
import { Form, Select, Input } from "antd";
import PropTypes from "prop-types";
//添加form组件
const Item = Form.Item;
const Option = Select.Option;
export default class AddForm extends Component {
  formRef = React.createRef();
  static propTypes = {
    setForm: PropTypes.func.isRequired,
    categorys: PropTypes.array.isRequired, //一级分类数组
    parentId: PropTypes.string.isRequired, //父分类的ID
  };
  render() {
    this.props.setForm(this.formRef);
    const { categorys, parentId } = this.props;
    return (
      <Form onFinish={this.onFinish}>
        <Item name={parentId}>
          <Select>
            <Option Value="0">一级分类</Option>
            {categorys.map((c) => (
              <Option Value={c._id}>{c.name}</Option>
            ))}
          </Select>
        </Item>
        <Item>
          <Input placeholder="输入分类名称" />
        </Item>
      </Form>
    );
  }
}
